#include "FWSprite.h"
#include "FWTexture.h"
#include "FWGraphic.h"
#include "ShareComponent.h"

FWSprite::FWSprite(void)
{	
}
FWSprite::FWSprite(FWTexture* texture, int spritePerRow,int spriteCount)
{
	this->_texture = texture;
	this->_spritePerRow = spritePerRow;
	this->_spriteCount = spriteCount;
	this->_sprite = NULL;
	this->_index = 0;
}
void FWSprite::reset(int index)
{
	this->_index = index;
}
void FWSprite::next()
{
	this->_index =(this->_index+1)%this->_spriteCount;
}
FWTexture* FWSprite::getTexture()
{
	return this->_texture;
}
void FWSprite::render(D3DXVECTOR2 position)
{
	RECT frame;
	frame.left = (this->_index % this->_spritePerRow)*(this->getTexture()->getWidth() / this->_spritePerRow);
	frame.right = frame.left + (this->getTexture()->getWidth()/this->_spritePerRow);
	frame.top =  (this->_index / this->_spritePerRow)*(this->getTexture()->getHeight() / this->_spritePerRow * this->_spriteCount);
	frame.bottom=frame.top + (this->getTexture()->getHeight() / this->_spritePerRow * this->_spriteCount);

	RECT des;
	des.top = position.y;
	des.left = position.x;
	des.bottom=des.top + (this->getTexture()->getHeight() / this->_spritePerRow * this->_spriteCount);
	des.right = des.left + (this->getTexture()->getWidth()/this->_spritePerRow);	
	this->center.y = (this->getTexture()->getHeight() / this->_spritePerRow * this->_spriteCount)/2;
	center.x = (this->getTexture()->getWidth() / this->_spritePerRow)/2;
	glGraphic->DrawTexture(this->_texture,frame,des,center,D3DCOLOR_XRGB(255,255,255),1);
}
void FWSprite::draw()
{
	
}
FWSprite::~FWSprite(void)
{
}
